﻿using Autofac;
using System.Windows;

namespace DXApp
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private readonly DiContainerBuilder _mainBuilder = new();
        private ILifetimeScope? _scope;

        protected override void OnStartup(StartupEventArgs e)
        {
            var dependencyContainer = _mainBuilder.GetBuiltContainer(); 
            _scope = dependencyContainer.BeginLifetimeScope();
            var exceptionHandler = _scope.Resolve<ExceptionHandler>();
            exceptionHandler.SetupExceptionHandlingEvents(this);

            var mainWindow = _scope.Resolve<MainWindow>();
            mainWindow.Show();

        }

        protected override void OnExit(ExitEventArgs e)
        {
            _scope.Dispose(); 
            base.OnExit(e);
        }

    }
}
